package vip.xiaonuo.smzq.modular.hisi.controller;

import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.smzq.core.tools.excel.ExcelToReadUtil;
import vip.xiaonuo.smzq.modular.hisi.entity.HisiDrkq;
import vip.xiaonuo.smzq.modular.hisi.entity.HisiKs;
import vip.xiaonuo.smzq.modular.hisi.entity.param.ZyclBhlParam;
import vip.xiaonuo.smzq.modular.hisi.entity.vo.*;
import vip.xiaonuo.smzq.modular.hisi.service.IHisiKsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.smzq.modular.jsc.entity.vo.Kcfb;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;


/**
 * 矿山信息
 *
 * @author eomer
 * @since 2024-02-22
 */
@Api(tags = "矿山信息")
@RestController
@RequestMapping("/hisi/hisiKs")
@Validated
public class HisiKsController {

    @Resource
    private IHisiKsService iHisiKsService;

    /**
     * 添加矿山信息
     */
    @ApiOperation("添加矿山信息")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid HisiKs hisiKs) {
        iHisiKsService.save(hisiKs);
        return CommonResult.ok();
    }

    /**
     * 删除矿山信息
     */
    @ApiOperation("删除矿山信息")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iHisiKsService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑矿山信息
     */
    @ApiOperation("编辑矿山信息")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid HisiKs hisiKs) {
        iHisiKsService.updateById(hisiKs);
        return CommonResult.ok();
    }

    /**
     * 矿山信息分页查询
     * 矿产地信息分页查询
     */
    @ApiOperation("矿山信息分页查询&&矿产地信息分页查询")
    @PostMapping("/pageHisiKs")
    public CommonResult<Page<Ksxicx>> pageHisiKs(
            @RequestBody @Valid CxtjMhtj cxtjMhtj
    ) {
        return CommonResult.data(iHisiKsService.pageHisiKs(cxtjMhtj));
    }
    /**
     * 矿山信息数量查询
     * 矿产地信息数量查询
     */
    @ApiOperation("矿山信息数量查询&&矿产地信息数量查询")
    @PostMapping("/getCxtjsljs")
    public CommonResult<Cxtjsljs> getCxtjsljs(
            @RequestBody @Valid CxtjMhtj cxtjMhtj
    ) {
        return CommonResult.data(iHisiKsService.getCxtjsljs(cxtjMhtj));
    }


    /**
     * 资源储量查询
     */
    @ApiOperation("资源储量查询")
    @PostMapping("/pageZyclcx")
    public CommonResult<Page<Zyclcx>> pageZyclcx(
            @RequestBody @Valid CxtjMhtj cxtjMhtj
    ) {
        return CommonResult.data(iHisiKsService.pageZyclcx(cxtjMhtj));
    }
    /**
     * 资源储量查询
     */
    @ApiOperation("资源储量数量查询")
    @PostMapping("/getZyclCount")
    public CommonResult<ZyclCount> getZyclCount(
            @RequestBody @Valid CxtjMhtj cxtjMhtj
    ) {
        return CommonResult.data(iHisiKsService.selectZyclCount(cxtjMhtj));
    }

    /**
     * 资源储量查询统计-重构
     *
     * @param cxtjMhtj
     * @author Kevin
     * @since 2024/7/6 11:38
     */
    @ApiOperation("资源储量查询-重构")
    @PostMapping("/pageZyclVo")
    public CommonResult<Page<ZyclVo>> pageZyclVo(@RequestBody @Valid CxtjMhtj cxtjMhtj) {
        return CommonResult.data(iHisiKsService.pageZyclVo(cxtjMhtj));
    }

    /**
     * 资源储量查询统计总量-重构
     *
     * @param cxtjMhtj
     * @author Kevin
     * @since 2024/7/6 11:38
     */
    @ApiOperation("资源储量查询总量-重构")
    @PostMapping("/getZyclTotal")
    public CommonResult<ZyclCountVo> getZyclTotal(@RequestBody @Valid CxtjMhtj cxtjMhtj) {
        return CommonResult.data(iHisiKsService.getZyclTotal(cxtjMhtj));
    }

    /**
     * 矿产地规模统计
     */
    @ApiOperation("矿产地规模统计")
    @GetMapping("/kcdgmtjList")
    public CommonResult<List<Kcdgmtj>> kcdgmtjList(Integer nd,String kzbh) {
        return CommonResult.data(iHisiKsService.getKcdgmtjList(nd,kzbh));
    }

    /**
     * 矿产地规模统计-重构
     *
     * @param nd
     * @param kzbh
     * @author Kevin
     * @since 2024/7/5 19:11
     * @Todo 接口优化
     */
    @ApiOperation("矿产地规模统计-重构")
    @GetMapping("/getKcdgmtjList")
    public CommonResult<List<KcdgmtjVo>> getKcdgmtjListNew(@ApiParam(name = "nd", value = "年度") @RequestParam(required = false) Integer nd,
                                                        @ApiParam(name = "kzbh", value = "矿种") @RequestParam(required = false) String kzbh) {
        return CommonResult.data(iHisiKsService.getKcdgmtjListNew(nd, kzbh));
    }

    @ApiOperation("矿产地分布")
    @GetMapping("/KcfbList")
    public CommonResult<List<Kcfb>> KcfbList(Integer nd,String xzqh) {

        return CommonResult.data(iHisiKsService.getkcfbList(nd,xzqh));
    }

    /**
     * 查询统计数据导出
     */
    @ApiOperation("查询统计数据导出")
    @GetMapping("/exportQueryKcfb")
    public void exportQueryKcfb(
           Integer nd, HttpServletResponse response
    ) {
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("ContentType", "application/vnd.ms-excel");
        //response.setHeader("Content-Disposition", "attachment; filename=111.xlsx");
        response.setCharacterEncoding("UTF-8");
        iHisiKsService.exportQueryKcfb(nd,response);
    }



    /**
     * 查询统计数据导出
     */
    @ApiOperation("查询统计数据导出_矿权")
    @PostMapping("/exportQuerykq")
    public void exportQueryStatistics(
            @RequestPart(value = "file", required = false) MultipartFile file, // 新增：接收文件流
            @Validated  CxtjMhtj cxtjMhtj, HttpServletResponse response
    ) {
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("ContentType", "application/vnd.ms-excel");
        //response.setHeader("Content-Disposition", "attachment; filename=111.xlsx");
        response.setCharacterEncoding("UTF-8");
        iHisiKsService.exportQueryStatistics(cxtjMhtj,file,response);
    }
    /**
     * 查询统计数据导出
     */
    @ApiOperation("查询统计数据导出")
    @PostMapping("/exportQuery")
    public void exportQueryStatistics(
            @RequestBody @Valid   CxtjMhtj cxtjMhtj, HttpServletResponse response
    ) {
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("ContentType", "application/vnd.ms-excel");
        //response.setHeader("Content-Disposition", "attachment; filename=111.xlsx");
        response.setCharacterEncoding("UTF-8");
        iHisiKsService.exportQueryStatistics(cxtjMhtj,null,response);
    }

    /**
     * 矿山数据更新同步
     */
    @ApiOperation("矿山数据更新同步")
    @PostMapping("/updateKsData")
    public CommonResult<Boolean> updateKsData(Integer nd,String xzqh){


        return CommonResult.data(iHisiKsService.updateKsData(nd,xzqh));
    }


    /**
     * 多年年初年末保有量的变化量查询测试
     */
//    @ApiOperation("多年年初年末保有量的变化量")
    @GetMapping("/exportZyclBhl/{nd}")
    public CommonResult<String> exportZyclBhl(@PathVariable("nd") String nd){
        iHisiKsService.exportZyclBhl(nd);
        return CommonResult.ok();
    }

    /**
     * 多年年初年末保有量的变化量-分页查询
     */
    @ApiOperation("多年年初年末保有量的变化量-分页查询")
    @PostMapping("/pageZyclBhl")
    public CommonResult<Map<String, Object>> pageZyclBhl(@RequestBody @Valid ZyclBhlParam param){
        return CommonResult.data(iHisiKsService.pageZyclBhl(param));
    }

    /**
     * 多年年初年末保有量的变化量-导出Excel
     */
    @ApiOperation("多年年初年末保有量的变化量-导出Excel")
    @PostMapping("/exportZyclBhl")
    public void exportZyclBhl(@RequestBody @Valid ZyclBhlParam param, HttpServletResponse response) {
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("ContentType", "application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        iHisiKsService.exportZyclBhl(param,response);
    }


}
